package com.hongsen.cn.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.hongsen.cn.base.BaseRecyclerViewHolder;
import com.hongsen.cn.bean.OrderBean;
import com.hongsen.cn.bean.TheKeyPersonelBean;
import com.hongsen.cn.dayandmonth.R;
import com.hongsen.cn.dayandmonth.databinding.ItemOutOfLineBinding;
import com.hongsen.cn.dayandmonth.databinding.ItemWorkDescBinding;
import com.hongsen.cn.listener.OnItemClickListener;

import java.util.ArrayList;
import java.util.List;

public class WorkDescAdapter extends RecyclerView.Adapter<BaseRecyclerViewHolder> {
    private List<OrderBean> strings = new ArrayList<>();
    private Context mcontext;
    public OnItemClickListener mOnItemClickLitener;
    public String type ;//1.今日违规， 2.今日加戴械具，3.风险人员（风险登记为123的），4.今日出所人员

    public WorkDescAdapter(Context context, List<OrderBean> strings,String type) {
        this.mcontext = context;
        this.strings = strings;
        this.type = type;
    }

    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemWorkDescBinding functionBinding = DataBindingUtil.inflate(LayoutInflater.from(mcontext),
                R.layout.item_work_desc, parent, false);
        functionBinding.setAdapter(this);
        return new TourViewHolder(functionBinding);
    }

    @Override
    public void onBindViewHolder(final BaseRecyclerViewHolder holder, final int position) {
        holder.bindData(strings.get(position));
        TourViewHolder tv = (TourViewHolder) holder;

        switch (type) {
            case "定位警情":
                tv.tvModuleLine.setVisibility(View.GONE);
                tv.tvModuleStatus.setVisibility(View.GONE);
                break;
            default:
        }

        /**
         * 背景颜色变化
         */
        if (position%2 == 0) {
            tv.llModuleBg.setBackgroundResource(R.color.c_3657A6);
        }else{
            tv.llModuleBg.setBackgroundResource(R.color.c_2c4c9A);
        }


        if (mOnItemClickLitener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemClick(holder.itemView, pos);
                }
            });

            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemLongClick(holder.itemView, pos);
                    return false;
                }
            });
        }
    }

    public void setOnItemClickLitener(OnItemClickListener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    @Override
    public int getItemCount() {
        return strings.size();
    }

    public class TourViewHolder extends BaseRecyclerViewHolder<OrderBean> {
        ItemWorkDescBinding binding;
        TextView tvModuleStatus,tvModuleLine;
        LinearLayout llModuleBg;

        public TourViewHolder(ItemWorkDescBinding dataBinding) {
            super(dataBinding.getRoot());
            binding = dataBinding;
            tvModuleStatus = dataBinding.tvModuleStatus;
            llModuleBg = dataBinding.llModuleBg;
            tvModuleLine = dataBinding.tvModuleLine;
        }

        @Override
        public void bindData(OrderBean data) {
            binding.setBean(data);
        }
    }

    @Override
    public int getItemViewType(int position) {
        return strings.size();
    }

}
